package cn.com.zs.android.service;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import cn.com.zs.android.model.GameParams;
import cn.com.zs.android.util.GameUtil;
import cn.com.zs.android.util.MusicPlayerUtils;

/**
 * 播放背景音乐的Service
 * @author 曾帅
 */
public class BackGroundMusicService extends Service {
	
	public static MusicPlayerUtils musicPlayer;
	
	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		// TODO Auto-generated method stub
		BackGroundMusicService.playMusic(getApplicationContext());
		return super.onStartCommand(intent, flags, startId);
	}

	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		BackGroundMusicService.stopMusic();
	}
	
	public static void playMusic(Context context) {
		if(GameParams.isBackgroundMusic) {
			if(musicPlayer == null) {
				musicPlayer = new MusicPlayerUtils();
			}
			musicPlayer.playMusic(context, GameUtil.backgroundMusicList);
		}
	}
	
	public static void goonMusic() {
		if (musicPlayer != null) {
			musicPlayer.goonMusic();
		}
	}
	
	public static void pauseMusic() {
		if (musicPlayer != null) {
			musicPlayer.pauseMusic();
		}
	}
	
	public static void stopMusic() {
		if (musicPlayer != null) {
			musicPlayer.stopMusic();
		}
	}
	
}
